<?php

use yii\helpers\Html;
use yii\bootstrap\ActiveForm;
use kartik\select2\Select2;
use app\modules\Manage\models\User;

$company = \Yii::$app->params['company'];
if($model->company){
    $model->company = json_decode($model->company);
}

$user = User::All();
$user_arr = [];
$user_arr = \yii\helpers\ArrayHelper::map($user,'id','name');

if($model->manage_user_id){
    $model->manage_user_id = json_decode($model->manage_user_id);
}

?>

<div class="user-form">

    <?php $form = ActiveForm::begin([
             'options' => ['enctype' => 'multipart/form-data',],
             'layout' => 'horizontal',
             'fieldConfig' => [
                'template' => "{label}\n{beginWrapper}\n{input}\n{hint}\n{error}\n{endWrapper}",
                'horizontalCssClasses' => [
                    'label' => 'col-sm-2',
                    'wrapper' => 'col-sm-7',
                    'error' => '',
                ],
             ],
        ]); ?>

    <?= $form->field($model, 'username')->textInput(['maxlength' => true]) ?>

    <?= $form->field($model, 'password')->textInput(['maxlength' => true]) ?>

    <?= $form->field($model, 'email')->textInput(['maxlength' => true]) ?>

    <?= $form->field($model, 'name')->textInput(['maxlength' => true]) ?>

    <?= $form->field($model, 'code')->textInput(['maxlength' => true]) ?>

    <?= $form->field($model, 'company')->widget(Select2::classname(), [
                'data' => $company,
                'language' => 'zh-cn',
                'options' => ['multiple' => true,'placeholder' => '所在公司'],
                'pluginOptions' => [
                    'allowClear' => true,
                ],
            ]);  ?>

    <?= $form->field($model, 'nation')->inline(true)->radioList(Yii::$app->params['nation']) ?>

    <?= $form->field($model, 'manage_user_id')->widget(Select2::classname(), [
                'data' => $user_arr,
                'language' => 'zh-cn',
                'options' => ['multiple' => true,'placeholder' => '管理人员'],
                'pluginOptions' => [
                    'allowClear' => true,
                ],
            ]);  ?>

    <div class="form-group text-center">
        <?= Html::submitButton(Yii::t('app', 'Save'), ['class' => 'btn btn-success']) ?>
    </div>

    <?php ActiveForm::end(); ?>

</div>
